package com.codinfguture.demo;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @Author kobe
 * @Date 2021/10/28 14:48
 * @Description 码上未来选秀大会
 */
public class Main {

    public static void main(String[] args) {

        // 球员姓名
        String[] names = new String[0];
        // 球员年龄
        int[] ages = new int[0];
        // 球队名称
        String[] teams = new String[0];
        // 职业类型
        String[] types = new String[0];

        // 姓名
        String[] namesNew = new String[0];
        // 年龄
        int[] agesNew = new int[0];
        // 球队
        String[] teamsNew = new String[0];
        // 职业类型
        String[] typesNew = new String[0];

        names = Arrays.copyOf(names, names.length + 5);
        ages = Arrays.copyOf(ages, ages.length + 5);
        teams = Arrays.copyOf(teams, teams.length + 5);
        types = Arrays.copyOf(types, types.length + 5);

        types[0] = "后卫";
        names[0] = "科比";
        ages[0] = 34;
        teams[0] = "湖人队";

        types[1] = "前锋";
        names[1] = "詹姆斯";
        ages[1] = 30;
        teams[1] = "湖人队";

        types[2] = "中锋";
        names[2] = "姚明";
        ages[2] = 31;
        teams[2] = "火箭队";

        types[3] = "后卫";
        names[3] = "乔丹";
        ages[3] = 52;
        teams[3] = "公牛队";

        types[4] = "后卫";
        names[4] = "纳什";
        ages[4] = 35;
        teams[4] = "太阳队";

        Scanner input = new Scanner(System.in);
        int choose;
        do {
            System.out.println();
            System.out.println("----------欢迎来到码上未来选秀大会---------");
            System.out.println("1.显示所有球员信息");
            System.out.println("2.根据年龄从小到大排列");
            System.out.println("3.随机观看球员技能展示");
            System.out.println("4.根据职业类型查找球员");
            System.out.println("5.删除球员");
            System.out.println("6.添加球员");
            System.out.println("0.退出");
            System.out.println();
            System.out.println("用户输入选择：");
            choose = input.nextInt();
            switch (choose) {
                case 1:
                    boolean isShow = true;
                    System.out.println("显示所有球员信息");
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] != null) {
                            isShow = false;
                            System.out.println("职业：" + types[i] + ",姓名：" + names[i] + ",年龄" + ages[i] + ",球队：" + teams[i]);
                        }
                    }
                    if (isShow) {
                        System.out.println("没有球员信息");
                    }
                    break;
                case 2:
                    namesNew = Arrays.copyOf(names, names.length);
                    agesNew = Arrays.copyOf(ages, ages.length);
                    teamsNew = Arrays.copyOf(teams, teams.length);
                    typesNew = Arrays.copyOf(types, types.length);
                    // 冒泡排序 排New 在排New数组之前 要把就数组的信息 拷贝给New数组
                    for (int i = 0; i < agesNew.length - 1; i++) {
                        for (int j = 0; j < agesNew.length - 1 - i; j++) {
                            if (agesNew[j] > agesNew[j + 1]) {
                                int desk = agesNew[j + 1];
                                agesNew[j + 1] = agesNew[j];
                                agesNew[j] = desk;

                                String desk1 = namesNew[j + 1];
                                namesNew[j + 1] = namesNew[j];
                                namesNew[j] = desk1;

                                String desk2 = teamsNew[j + 1];
                                teamsNew[j + 1] = teamsNew[j];
                                teamsNew[j] = desk2;

                                String desk3 = typesNew[j + 1];
                                typesNew[j + 1] = typesNew[j];
                                typesNew[j] = desk3;
                            }
                        }
                    }

                    for (int i = 0; i < namesNew.length; i++) {
                        if (namesNew[i] != null) {
                            System.out.println(
                                    "职业：" + typesNew[i] + ",姓名：" + namesNew[i] + ",年龄" + agesNew[i] + ",球队：" + teamsNew[i]);
                        }
                    }
                    System.out.println("根据年龄从小到大排列");
                    break;
                case 3:
                    Random random = new Random();
                    String isContinue = null;
                    do {
                        int ran = random.nextInt(names.length);

                        System.out.println("职业：" + types[ran] + "," + "姓名:" + names[ran] + "," + "年龄：" + ages[ran] + ","
                                + "球队：" + teams[ran]);
                        System.out.println("技能展示");
                        switch (types[ran]) {
                            case "后卫":
                                System.out.println("Crossover突破上篮");
                                break;
                            case "前锋":
                                System.out.println("大风车极限扣篮");
                                break;
                            case "中锋":
                                System.out.println("梦幻脚步勾手上篮");
                                break;
                        }
                        System.out.print("是否继续y/任意键返回》》》");
                        isContinue = input.next();
                    } while (isContinue.equals("y"));
                    break;
                case 4:
                    boolean isExit = false;
                    System.out.println("根据职业类型查找球员");
                    System.out.println("输入要查找的职业(后卫/中锋/前锋)");
                    String type = input.next();
                    for (int i = 0; i < names.length; i++) {
                        if (type.equals(types[i])) {
                            isExit = true;
                            System.out.println("职业:" + types[i] + "," + "姓名:" + names[i] + "," + "年龄：" + ages[i] + ","
                                    + "球队：" + teams[i]);
                        }
                    }
                    if (!isExit) {
                        System.out.println("输入有误");
                    }
                    break;
                case 5:
                    System.out.println("删除球员");
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] != null) {
                            System.out.println("职业：" + (i + 1) + "\t" + types[i] + "," + "姓名:" + names[i] + "," + "年龄："
                                    + ages[i] + "," + "球队：" + teams[i]);
                        }
                    }
                    System.out.print("输入要删除的球员序号：");
                    int number = input.nextInt();
                    if (number <= names.length && names[number - 1] != null) {
                        // 循环移位
                        for (int j = number - 1; j < names.length - 1; j++) {
                            names[j] = names[j + 1];
                            ages[j] = ages[j + 1];
                            types[j] = types[j + 1];
                            teams[j] = teams[j + 1];
                        }
                        // 最后一位清空
                        names[names.length - 1] = null;
                        ages[names.length - 1] = 0;
                        names[names.length - 1] = null;
                        teams[names.length - 1] = null;
                        System.out.println("删除成功！");
                    } else {
                        System.out.println("要删除的球员信息不存在");
                    }
                    break;
                case 6:
                    System.out.println("添加球员");
                    boolean isAddSport = false;
                    System.out.print("请输入需要添加的球员职业：");
                    String typeSport = input.next();
                    System.out.print("请输入球员名称：");
                    String nameSport = input.next();
                    System.out.print("请输入球员年龄：");
                    int ageSport = input.nextInt();
                    System.out.print("请输入球员球队名称：");
                    String teamSport = input.next();
                    for (int i = 0; i < names.length; i++) {
                        // 如果用户输入的 姓名和职业类型 与原数组中有相同的了, 添加失败
                        if (nameSport.equals(names[i]) && typeSport.equals(types[i])) {
                            isAddSport = true;
                        }
                    }
                    if (!isAddSport) {
                        names = Arrays.copyOf(names, names.length + 1);
                        ages = Arrays.copyOf(ages, ages.length + 1);
                        teams = Arrays.copyOf(teams, teams.length + 1);
                        types = Arrays.copyOf(types, types.length + 1);

                        names[names.length - 1] = nameSport;
                        types[names.length - 1] = typeSport;
                        ages[names.length - 1] = ageSport;
                        teams[names.length - 1] = teamSport;
                        System.out.println("添加成功");
                    }
                    if (isAddSport) {
                        System.out.println("球员姓名有重复添加失败");
                    }
                    break;
                case 0:
                    break;
                default:
                    System.out.println("输入有误，请重新输入!");
                    break;
            }
        } while (choose != 0);
        System.out.println("欢迎下次再来选秀！");
    }

}

